home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 22 code / PCI Driver Sample / NCR_DriverProject / Src / GetDevicePowerInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-19  |  3.4 KB  |  108 lines  |  [TEXT/MPCC]

  1. /*                                    GetDevicePowrInfo.c                                */
  2. /*
  3.  * GetDevicePowrInfo.c
  4.  * Copyright © 1994-95 Apple Computer Inc. All rights reserved.
  5.  *
  6.  */
  7. /*    .___________________________________________________________________________________.
  8.       | These routines, after modification, will be useful for other drivers. There are    |
  9.       | several general-purpuse routines that simplify access to the Name Registry. There    |
  10.     | are also some routines that are specific to the sample driver that will be useful    |
  11.     | for other drivers after modification.                                                |
  12.     .___________________________________________________________________________________.
  13. */
  14.  
  15. #include "NCRDriverPrivate.h" 
  16. /*
  17.  * IEEE 1275 defines the "power-consumption" property.
  18.  */
  19. #define kDevicePowerProperty        "power-consumption"
  20. /*
  21.  * Power values are encoded in a vector of "maximum in microwatts." Unspecified values
  22.  * shall be zero if other values are provided. Power consumption is zero for missing
  23.  * values. If the property is missing, the default value will be used.
  24.  */
  25. enum {
  26.     kUnspecifiedStandby,
  27.     kUnspecifiedFullPower,
  28.     kFiveVoltStandby,
  29.     kFiveVoltFullPower,
  30.     kThreeVoltStandby,
  31.     kThreeVoltFullPower,
  32.     kIOPowerStandby,
  33.     kIOPowerFullPower,
  34.     kReservedStandby,
  35.     kReservedFullPower
  36. };
  37.  
  38. /*
  39.  * The function uses this structure to equate registry entry values with
  40.  * DriverGestalt selectors.
  41.  */
  42. typedef struct PowerInfo {
  43.     OSType                driverGestaltSelector;
  44.     short                correctIndex;
  45.     short                fallbackIndex;
  46. } PowerInfo;
  47. static const PowerInfo    gPowerInfo[] = {
  48.     { kDriverGestalt5MaxHighPower,    kFiveVoltFullPower,        kUnspecifiedFullPower    },
  49.     { kDriverGestalt5MaxLowPower,    kFiveVoltStandby,        kUnspecifiedStandby        },
  50.     { kDriverGestalt3MaxHighPower,    kThreeVoltFullPower,    kUnspecifiedFullPower    },
  51.     { kDriverGestalt3MaxLowPower,    kThreeVoltStandby,        kUnspecifiedStandby        },
  52.     { 0,                            0,                        0                        }
  53. };
  54.  
  55. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  56.  * Retrieve the driver power consumption vector and search it for the desired power
  57.  * consumption value. Return the desired value, or a default value if the desired
  58.  * value is unavailable. This function does not allocate memory or return any errors.
  59.  */
  60. UInt32
  61. GetDevicePowerConsumption(
  62.         RegEntryIDPtr            regEntryIDPtr,            /* Driver's Name Registery ID    */
  63.         OSType                    driverGestaltSelector,    /* PBStatus parameter            */
  64.         UInt32                    defaultPowerConsumption    /* Default return value            */
  65.     )
  66. {
  67.         OSErr                    status;
  68.         UInt32                    result;
  69.         short                    i;
  70.         short                    index;
  71.         ItemCount                nValues;
  72.         RegPropertyValueSize    size;
  73.         UInt32                    microWatts[kReservedFullPower];
  74.  
  75.         Trace(GetDevicePowerConsumption);
  76.         result = defaultPowerConsumption;
  77.         status = RegistryPropertyGetSize(
  78.                     regEntryIDPtr,
  79.                     kDevicePowerProperty,
  80.                     &size
  81.                 );
  82.         if (status == noErr && size <= sizeof microWatts) {
  83.             status = RegistryPropertyGet(
  84.                         regEntryIDPtr,
  85.                         kDevicePowerProperty,
  86.                         (RegPropertyValue *) microWatts,
  87.                         &size
  88.                     );
  89.         }
  90.         CheckStatus(status, "\pCan't retrieve power-consumption");
  91.         if (status == noErr) {
  92.             nValues = size / sizeof microWatts[0];
  93.             for (i = 0; gPowerInfo[i].driverGestaltSelector != 0; i++) {
  94.                 if (gPowerInfo[i].driverGestaltSelector == driverGestaltSelector) {
  95.                     index = gPowerInfo[i].correctIndex;
  96.                     if (index >= nValues)
  97.                         index = gPowerInfo[i].fallbackIndex;
  98.                     if (index < nValues)
  99.                         result = microWatts[index];
  100.                     break;
  101.                 }
  102.             }
  103.         }
  104.         return (result);
  105. }
  106.  
  107.  
  108.